﻿namespace PersonalBudgeting.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class First : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Expenses",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Name = c.String(),
                        Amount = c.Decimal(nullable: false, precision: 18, scale: 2),
                        Date = c.DateTime(nullable: false),
                        ExpensesCategory_Id = c.Guid(),
                        User_Id = c.Guid(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ExpensesCategories", t => t.ExpensesCategory_Id)
                .ForeignKey("dbo.Users", t => t.User_Id)
                .Index(t => t.ExpensesCategory_Id)
                .Index(t => t.User_Id);
            
            CreateTable(
                "dbo.ExpensesCategories",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Users",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Login = c.String(nullable: false, maxLength: 50),
                        Email = c.String(nullable: false),
                        Phone = c.String(),
                        Password = c.String(nullable: false),
                        IsAgree = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Incomes",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Name = c.String(),
                        Amount = c.Decimal(nullable: false, precision: 18, scale: 2),
                        Date = c.DateTime(),
                        IsRealized = c.Boolean(nullable: false),
                        IncomesCategory_Id = c.Guid(),
                        User_Id = c.Guid(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.IncomesCategories", t => t.IncomesCategory_Id)
                .ForeignKey("dbo.Users", t => t.User_Id)
                .Index(t => t.IncomesCategory_Id)
                .Index(t => t.User_Id);
            
            CreateTable(
                "dbo.IncomesCategories",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.MandatoryExpenses",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Name = c.String(),
                        Amount = c.Decimal(nullable: false, precision: 18, scale: 2),
                        Date = c.DateTime(),
                        IsRealized = c.Boolean(nullable: false),
                        MandatoryExpensesCategory_Id = c.Guid(),
                        User_Id = c.Guid(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.MandatoryExpensesCategories", t => t.MandatoryExpensesCategory_Id)
                .ForeignKey("dbo.Users", t => t.User_Id)
                .Index(t => t.MandatoryExpensesCategory_Id)
                .Index(t => t.User_Id);
            
            CreateTable(
                "dbo.MandatoryExpensesCategories",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.MandatoryExpenses", "User_Id", "dbo.Users");
            DropForeignKey("dbo.MandatoryExpenses", "MandatoryExpensesCategory_Id", "dbo.MandatoryExpensesCategories");
            DropForeignKey("dbo.Incomes", "User_Id", "dbo.Users");
            DropForeignKey("dbo.Incomes", "IncomesCategory_Id", "dbo.IncomesCategories");
            DropForeignKey("dbo.Expenses", "User_Id", "dbo.Users");
            DropForeignKey("dbo.Expenses", "ExpensesCategory_Id", "dbo.ExpensesCategories");
            DropIndex("dbo.MandatoryExpenses", new[] { "User_Id" });
            DropIndex("dbo.MandatoryExpenses", new[] { "MandatoryExpensesCategory_Id" });
            DropIndex("dbo.Incomes", new[] { "User_Id" });
            DropIndex("dbo.Incomes", new[] { "IncomesCategory_Id" });
            DropIndex("dbo.Expenses", new[] { "User_Id" });
            DropIndex("dbo.Expenses", new[] { "ExpensesCategory_Id" });
            DropTable("dbo.MandatoryExpensesCategories");
            DropTable("dbo.MandatoryExpenses");
            DropTable("dbo.IncomesCategories");
            DropTable("dbo.Incomes");
            DropTable("dbo.Users");
            DropTable("dbo.ExpensesCategories");
            DropTable("dbo.Expenses");
        }
    }
}
